package gui.menu;

import gui.AnzeigeButton;
import gui.MenuButton;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import control.OptionsMenuManager;
import data.ChallengeData;
import data.Options;

public class OptionsMenu extends JPanel implements Menu{

	private MenuButton difficulty;

	private Options opt;
	private ChallengeData[] challengedata;

	private AnzeigeButton anzeigebuttons[];
	private AnzeigeButton difficultyanzeige;
	
	private JPanel menu;

	
	public OptionsMenu(OptionsMenuManager manager, Color bgcolor, Options options) {
		super();
		init(manager,bgcolor, options);
	}
	
	
	public void init(OptionsMenuManager manager, Color bgcolor, Options options){
		
		this.removeAll();
		
		opt = options;
		challengedata = opt.getChallenges();
		
		JPanel outer = new JPanel(new GridLayout(1,2));
		outer.setBackground(bgcolor);

		menu = new JPanel();
		setBackground(bgcolor);
		menu.setBackground(bgcolor);
		
		difficulty = new MenuButton("difficulty", manager,1.0f);

		JButton text = new JButton("Challenges");
		text.setFont(new Font("Calibri", 1, 30));
		text.setForeground(new Color(0, 160, 255));
        text.setBorderPainted(false);
        text.setContentAreaFilled(false);
        text.setFocusPainted(false);
        text.setAlignmentX(1.0f);
		
		
		BorderLayout border = new BorderLayout();
		setLayout(border);
		
		BoxLayout box = new BoxLayout(menu,BoxLayout.Y_AXIS);
		menu.setLayout(box);

		menu.add(difficulty);
		menu.add(text);
		
		for (Options.challengesEnum chall : Options.challengesEnum.values() ){
			menu.add(new MenuButton(chall.name(), manager, new Font("Calibri", 1, 20), 1.0f));
		}
		menu.add(new MenuButton("Back",manager, 1.0f));
		
		/* ##############  Right  #####################*/
		
		JPanel right = new JPanel();
		BoxLayout box1 = new BoxLayout(right,BoxLayout.Y_AXIS);
		right.setLayout(box1);
		right.setBackground(bgcolor);
		difficultyanzeige = new AnzeigeButton(opt.getDifficulty().name(), 30);
		right.add(difficultyanzeige);
		right.add(new MenuButton(" ", manager, 0.0f));
		
		anzeigebuttons = new AnzeigeButton[Options.challengesEnum.values().length];
		int i = 0;
		for (Options.challengesEnum chall : Options.challengesEnum.values() ){
			anzeigebuttons[i] = new AnzeigeButton(""+challengedata[chall.ordinal()].getRounds(), 20);
			right.add(anzeigebuttons[i]);
			i++;
		}

		
		outer.add(menu);
		outer.add(right);
		
		Box menuBox = Box.createVerticalBox();
		
		menuBox.add(Box.createVerticalBox());
		menuBox.add(Box.createVerticalGlue());
		menuBox.add(outer);
		menuBox.add(Box.createVerticalGlue());
		menuBox.add(Box.createVerticalBox());
		
		add(menuBox,BorderLayout.CENTER);
		update();

	}
	
	public void update(){
		int i=0;
		difficultyanzeige.setText(opt.getDifficulty().name());
		for (AnzeigeButton but : anzeigebuttons){
			if(challengedata[i].getRounds() == 0)but.setText("diasbled");
			else but.setText(""+challengedata[i].getRounds());
			i++;
		}
	}
//	public void show() {
//		setVisible(true);
//	}
//	
//	public void close() {
//		setVisible(false);
//	}
}
